//; ---------------------------------------------------------------------------
//; Object 29 - points that appear when you destroy something
//; ---------------------------------------------------------------------------
#include "points.h"

#include "../sprite.h"

static object *obj;

//; ---------------------------------------------------------------------------
//; Sprite mappings - points that	appear when you	destroy	something
//; ---------------------------------------------------------------------------
byte byte_94BC[] = {  1,
		 0xFC, 4, 0,  0, 0xF8
};                                     //; 100 points
byte byte_94C2[] = {  1,
		 0xFC, 4, 0,  2, 0xF8	
};                                     //; 200 points
byte byte_94C8[] = {  1,
		 0xFC, 4, 0,  4, 0xF8	
};                                     //; 500 points
byte byte_94CE[] = {  1,
		 0xFC, 8, 0,  6, 0xF8	
};                                     //;1000 points
byte byte_94D4[] = {  1,
		 0xFC, 0, 0,  6, 0xFC
};	                                //; 10 points
byte byte_94DA[] = {  2,
		 0xFC, 8, 0,  6, 0xF4,	//; 10,000 points
		 0xFC, 4, 0,  7,    1
};
byte byte_94E5[] = {  2,
		 0xFC, 8, 0,  6, 0xF4,	//; 100,000 points
		 0xFC, 4, 0,  7,    6
};

byte *Map_Poi[] = { byte_94BC, byte_94C2, byte_94C8, byte_94CE,
	            byte_94D4, byte_94DA, byte_94E5
};
//--------------

void (*Poi_Index[2])() = { Poi_Main, Poi_Slower };


//Points:					; XREF: Obj_Index
void Points(object *_obj)
{
    obj = _obj;

    //moveq	#0,d0
    //move.b	obRoutine(a0),d0
    byte routine = obj->Routine/2;

    //move.w	Poi_Index(pc,d0.w),d1
    //jsr	Poi_Index(pc,d1.w)
    (*Poi_Index[routine])();
		
    //bra.w	DisplaySprite
    DisplaySprite(obj);
}

//Poi_Main:	; Routine 0
void Poi_Main()
{
    //addq.b	#2,obRoutine(a0)
    obj->Routine = obj->Routine + 2;

    //move.l	#Map_Poi,obMap(a0)
    obj->Map = Map_Poi;

    //move.w	#$2797,obGfx(a0)
    obj->Gfx = 0x2797;

    //move.b	#4,obRender(a0)
    obj->Render = 4;

    //move.b	#1,obPriority(a0)
    obj->Priority = 1;

    //move.b	#8,obActWid(a0)
    obj->ActionWidth = 8;

    //move.w	#-$300,obVelY(a0) ; move object upwards
    obj->VelocityY = -0x300;

    Poi_Slower();
}

//Poi_Slower:	; Routine 2
void Poi_Slower()
{
    //tst.w	obVelY(a0)	; is object moving?	
    //bpl.w	DeleteObject	; if not, delete
    if (obj->VelocityY >= 0) { DeleteObject(obj); }
    else
    {
        //bsr.w	SpeedToPos
        SpeedToPos(obj);

	//addi.w	#$18,obVelY(a0)	; reduce object	speed
        obj->VelocityY = obj->VelocityY + 0x18;
      
        //rts
    }
}	
